﻿<Application x:Class="NthDownload.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:NthDownload" xmlns:NthDownloadConverters="clr-namespace:NthDownload.Converters">
    <Application.Resources>
        <!--Resource Dictionaries-->
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary>
                    <!--Caliburn Micro-->
                    <local:Bootstrapper x:Key="bootstrapper" />

                    <!--Converters-->
                    <NthDownloadConverters:BooleanToVisiblityConverter x:Key="BooleanToVisiblityTrueVisible" TrueValue="Visible" FalseValue="Collapsed" />
                    <NthDownloadConverters:BooleanToVisiblityConverter x:Key="BooleanToVisiblityFalseVisible" TrueValue="Collapsed" FalseValue="Visible" />
                    <NthDownloadConverters:BandwidthProviderNoneSelectionToNullConverter x:Key="BandwidthProviderNoneSelectionToNull" />
                    <NthDownloadConverters:BooleanInversionConverter x:Key="BooleanInversionConverter" />
                    
                    <!--Storyboards-->
                    <Storyboard x:Key="FadeIn" >
                        <DoubleAnimation Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0.5"/>
                    </Storyboard>

                    <Storyboard x:Key="FadeOut">
                        <DoubleAnimation Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:0.5" />
                    </Storyboard>
                    
                    <!--Buttons-->
                    <Style TargetType="Button">
                        <Setter Property="MinWidth" Value="50" />
                        <Setter Property="MinHeight" Value="20" />
                    </Style>

                    <Style x:Key="StyleLessButton" TargetType="Button">
                    </Style>

                    <Style x:Key="ListBoxMouseOverButton" TargetType="Button">
                        <Setter Property="Opacity" Value="0" />
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}}" Value="True">
                                <DataTrigger.EnterActions>
                                    <BeginStoryboard Storyboard="{StaticResource FadeIn}" />
                                </DataTrigger.EnterActions>
                                <DataTrigger.ExitActions>
                                    <BeginStoryboard Storyboard="{StaticResource FadeOut}" />
                                </DataTrigger.ExitActions>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>

                    <Style x:Key="TreeViewMouseOverButton" TargetType="Button">
                        <Setter Property="Opacity" Value="0" />
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Border}}}" Value="True">
                                <DataTrigger.EnterActions>
                                    <BeginStoryboard Storyboard="{StaticResource FadeIn}" />
                                </DataTrigger.EnterActions>
                                <DataTrigger.ExitActions>
                                    <BeginStoryboard Storyboard="{StaticResource FadeOut}" />
                                </DataTrigger.ExitActions>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>

                    <Style x:Key="ItemsControlStackPanelMouseOverButton" TargetType="Button">
                        <Setter Property="Opacity" Value="0" />
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type StackPanel}}}" Value="True">
                                <DataTrigger.EnterActions>
                                    <BeginStoryboard Storyboard="{StaticResource FadeIn}" />
                                </DataTrigger.EnterActions>
                                <DataTrigger.ExitActions>
                                    <BeginStoryboard Storyboard="{StaticResource FadeOut}" />
                                </DataTrigger.ExitActions>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>

                    <Style x:Key="PluginSelector" TargetType="Button">
                        <Setter Property="Width" Value="150" />
                        <Setter Property="Height" Value="150" />
                    </Style>

                    <Style x:Key="ScrollButton" TargetType="Button">
                        <Setter Property="Width" Value="20" />
                        <Setter Property="Height" Value="150" />
                    </Style>

                    <Style x:Key="XButton" TargetType="Button">
                        <Setter Property="Width" Value="20" />
                        <Setter Property="Height" Value="20" />
                    </Style>

                    <!--TextBox-->
                    <Style x:Key="TextBoxError" TargetType="TextBox">
                        <Style.Triggers>
                            <Trigger Property="Validation.HasError" Value="true">
                                <Setter Property="ToolTip"
                                        Value="{Binding RelativeSource={x:Static RelativeSource.Self},
                                                        Path=(Validation.Errors)[0].ErrorContent}"/>
                            </Trigger>
                        </Style.Triggers>
                    </Style>

                    <Style x:Key="MediumTextBox" TargetType="TextBox" BasedOn="{StaticResource TextBoxError}">
                        <Setter Property="Width" Value="300" />
                    </Style>

                    <!--PasswordBox-->
                    <Style x:Key="MediumPasswordBox" TargetType="PasswordBox">
                        <Setter Property="Width" Value="300" />
                    </Style>

                    <!--TextBlock-->
                    <Style x:Key="Label" TargetType="TextBlock">
                        <Setter Property="HorizontalAlignment" Value="Right" />
                        <Setter Property="VerticalAlignment" Value="Center" />
                    </Style>
                    
                    <!--ListBox-->
                    <Style TargetType="ListBox">
                        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                    </Style>

                    <!--TreeView-->
                    <!--<Style TargetType="TreeViewItem">
                        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                    </Style>-->

                    <!--<Style TargetType="TreeView">
                        <Setter Property="HorizontalAlignment" Value="Stretch" />
                        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                    </Style>-->
                    
                    <Style x:Key="StretchedTreeViewItems" TargetType="TreeViewItem">
                        <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
                        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="TreeViewItem">
                                    <StackPanel>
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="Auto" MinWidth="19" />
                                                <ColumnDefinition Width="*" />
                                            </Grid.ColumnDefinitions>
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="Auto" />
                                                <RowDefinition />
                                            </Grid.RowDefinitions>
                                            <ToggleButton IsChecked="{Binding Path=IsExpanded, RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press" Name="Expander">
                                                <ToggleButton.Style>
                                                    <Style TargetType="ToggleButton">
                                                        <Setter Property="UIElement.Focusable" Value="false" />
                                                        <Setter Property="FrameworkElement.Width" Value="16" />
                                                        <Setter Property="FrameworkElement.Height" Value="16" />
                                                        <Setter Property="Control.Template">
                                                            <Setter.Value>
                                                                <ControlTemplate TargetType="ToggleButton">
                                                                    <Border Padding="5,5,5,5"
                                                                            Background="#00FFFFFF"
                                                                            Width="16"
                                                                            Height="16">
                                                                        <Path Fill="#00FFFFFF"
                                                                             Stroke="#FF989898"
                                                                             Name="ExpandPath">
                                                                            <Path.Data>
                                                                                <PathGeometry Figures="M0,0L0,6L6,0z" />
                                                                            </Path.Data>
                                                                            <Path.RenderTransform>
                                                                                <RotateTransform Angle="135"
                                                                                                 CenterX="3"
                                                                                                 CenterY="3" />
                                                                            </Path.RenderTransform>
                                                                        </Path>
                                                                    </Border>
                                                                    <ControlTemplate.Triggers>
                                                                        <Trigger Property="UIElement.IsMouseOver" Value="True">
                                                                            <Setter TargetName="ExpandPath"
                                                                                    Property="Shape.Stroke"
                                                                                    Value="#FF1BBBFA" />
                                                                            <Setter TargetName="ExpandPath"
                                                                                    Property="Shape.Fill"
                                                                                    Value="#00FFFFFF" />
                                                                        </Trigger>
                                                                        <Trigger Property="ToggleButton.IsChecked" Value="True">
                                                                            <Setter TargetName="ExpandPath" Property="UIElement.RenderTransform">
                                                                                <Setter.Value>
                                                                                    <RotateTransform Angle="180"
                                                                                                     CenterX="3"
                                                                                                     CenterY="3" />
                                                                                </Setter.Value>
                                                                            </Setter>
                                                                            <Setter TargetName="ExpandPath"
                                                                                    Property="Shape.Fill"
                                                                                    Value="#FF595959" />
                                                                            <Setter TargetName="ExpandPath"
                                                                                    Property="Shape.Stroke"
                                                                                    Value="#FF262626" />
                                                                        </Trigger>
                                                                    </ControlTemplate.Triggers>
                                                                </ControlTemplate>
                                                            </Setter.Value>
                                                        </Setter>
                                                    </Style>
                                                </ToggleButton.Style>
                                            </ToggleButton>
                                            <Border x:Name="Bd"
                                                    HorizontalAlignment="Stretch"
                                                    BorderThickness="{TemplateBinding Border.BorderThickness}"
                                                    BorderBrush="{TemplateBinding Border.BorderBrush}"
                                                    Padding="{TemplateBinding Control.Padding}"
                                                    Background="{TemplateBinding Panel.Background}"
                                                    SnapsToDevicePixels="True"
                                                    Grid.Column="1">
                                                <ContentPresenter x:Name="PART_Header"
                                                                  Content="{TemplateBinding HeaderedContentControl.Header}"
                                                                  ContentTemplate="{TemplateBinding HeaderedContentControl.HeaderTemplate}"
                                                                  ContentStringFormat="{TemplateBinding HeaderedItemsControl.HeaderStringFormat}"
                                                                  ContentTemplateSelector="{TemplateBinding HeaderedItemsControl.HeaderTemplateSelector}"
                                                                  ContentSource="Header"
                                                                  HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
                                                                  SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
                                            </Border>
                                            <ItemsPresenter x:Name="ItemsHost"
                                                            Grid.Column="1"
                                                            Grid.Row="1" />
                                        </Grid>
                                    </StackPanel>
                                    <ControlTemplate.Triggers>
                                        <Trigger Property="TreeViewItem.IsExpanded" Value="False">
                                            <Setter TargetName="ItemsHost"
                                                    Property="UIElement.Visibility"
                                                    Value="Collapsed" />
                                        </Trigger>
                                        <Trigger Property="ItemsControl.HasItems" Value="False">
                                            <Setter TargetName="Expander"
                                                    Property="UIElement.Visibility"
                                                    Value="Hidden" />
                                        </Trigger>
                                        <Trigger Property="TreeViewItem.IsSelected" Value="True">
                                            <Setter TargetName="Bd" Property="Panel.Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
                                            <Setter Property="TextElement.Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}" />
                                        </Trigger>
                                        <MultiTrigger>
                                            <MultiTrigger.Conditions>
                                                <Condition Property="TreeViewItem.IsSelected" Value="True" />
                                                <Condition Property="Selector.IsSelectionActive" Value="False" />
                                            </MultiTrigger.Conditions>
                                            <Setter TargetName="Bd"
                                                    Property="Panel.Background"
                                                    Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
                                                                            <Setter Property="TextElement.Foreground"
                                                    Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
                                        </MultiTrigger>
                                        <Trigger Property="UIElement.IsEnabled" Value="False">
                                            <Setter Property="TextElement.Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
                                        </Trigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>

                    <!--ComboBox-->
                    <Style x:Key="MediumComboBox" TargetType="ComboBox">
                        <Setter Property="Width" Value="300" />
                    </Style>

                    <!--Grid-->
                    <Style TargetType="Grid">
                        <Setter Property="Validation.ErrorTemplate" Value="{x:Null}"/>
                    </Style>
                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>
